<?php

namespace addons\zzyy\module;



use app\admin\model\zzyy\ZzyyFeature;
use app\admin\model\zzyy\ZzyyRoom;

class Room
{
    static public function getRoomFormatInfo($id)
    {
        $room = ZzyyRoom::with('store')->find($id);
        if (!$room) {
            return  null;
        }

        $room->room_bannerimage = cdnurl($room->room_bannerimage, true);
        $room->room_slideimages = (function ($value) {
            $rows = explode(',', $value);
            return array_map(function ($e) {
                return cdnurl($e, true);
            }, $rows);
        })($room->room_slideimages);

        $room->features = (function ($ids) {
            $features = ZzyyFeature::whereIn('id', $ids)->select();
            return array_map(function ($e) {
                return [
                    'id' => $e->id,
                    'title' => $e->feature_name,
                ];
            }, $features);
        })($room->feature_ids);
        $room->store_name = $room->store->store_name;

        unset($room->rent_time);
        unset($room->store);

        return $room;
    }

}